from django.shortcuts import render
from datetime import datetime
# Create your views here.

def index(request):
    return render(request, 'index.html')

def info(request):
    # 1.普通变量
    username = 'zhj'
    # 2.字典类型
    book = {'name':'django','author':'zhj'}
    return render(request, 'info.html',context={'username':username,'book':book})

def info2(request):
    # 3.列表
    books = [
        {'name': 'django', 'author': 'zhj'},
        {'name': 'python', 'author': 'zhj'},
        {'name': 'nodejs', 'author': 'zhj'},
      ]
    context = {'books': books}
    return render(request,'info2.html',context=context)

def info3(request):
    # 对象
  class Person:
        def __init__(self, name, age):
            self.name = name
            self.age = age

  context = {
      'person': Person('zhj', 18),
      }
  return render(request,'info3.html',context=context)

def if_view(request):
    age = 17
    return render(request,'if.html',context={'age':age})

def for_view(request):
    # 1.列表
    books = [
        {'name': 'django', 'author': 'zhj'},
        {'name': 'python', 'author': 'zhj'},
        {'name': 'nodejs', 'author': 'zhj'},
    ]
    # 字典
    person = {
        'name': 'zhj',
        'age': 17,
        'height': 180
    }
    context = {'books': books, 'person': person}
    return render(request,'for.html',context)

def with_view(request):
    context = {
        'books' :[
        {'name': 'django', 'author': 'zhj'},
        {'name': 'python', 'author': 'zhj'},
        {'name': 'nodejs', 'author': 'zhj'},
    ]
    }

    return render(request,'with.html',context=context)

def url_view(request):
    return render(request,'url.html')

def filter_view(request):
    greet = "Hello World, Hello Django"
    context = {'greet': greet,'birthday':datetime.now(),'profile':"天空中最亮的星",'html':'<h1>欢迎来到zhj公司</h1>'}
    return render(request,'filter.html',context=context)

def template_form(request):
    context = {
        'articles':['deepseek','ChatGPT']
    }
    return render(request,'t_index.html',context=context)

def base_form(request):
    return render(request,'t_base.html')

def home_form(request):
    return render(request,'t_home.html')

def static_view(request):
    return render(request,'static.html')
